package gbench.appdemo.crawler.junit.jdbc;

import java.io.File;
import java.io.FileInputStream;
import java.util.Set;
import org.junit.jupiter.api.Test;
import gbench.appdemo.crawler.srch.JdbcSrchApplication;
import gbench.appdemo.crawler.srch.JdbcSrchApplication.JdbcSrchEngine;
import gbench.common.fs.FileSystem;

/**
 * 
 * @author gbench
 *
 */
public class JunitDataAnalyzer {
    /**
     * 
     */
    @SuppressWarnings("unchecked")
    @Test
    public void foo() {
        jdbc.initialize();
        final var home = "C:\\Users\\gbench\\Desktop\\中国笔记\\逻辑散文\\accp";
        JdbcSrchApplication.traverse2(new File(home), file->{
            try {
                FileSystem.bufferedRead(new FileInputStream(file), "utf8", br->{
                    br.lines().forEach(line->{
                        System.out.println(line);
                        jdbc.analyze(line).stream()
                        .filter(e->((Set<String>)e.get("tags")).contains("财会"))
                        .map(e->e.str("symbol"))
                        .distinct()
                        .forEach(word->{
                            System.out.println(word);
                        }); // forEach
                    });// forEach
                });// bufferedRead
                
            } catch (Exception e) {
                e.printStackTrace();
            }// try
        });// traverse
        
        jdbc.uninitialize();
    }
    
    public String indexHome = "indexes";// 索引文件的路径
    public String corpusHome = "C:\\Users\\gbench\\Desktop\\中国笔记\\逻辑词汇";// 语料库的词汇目录
    public String snapHome = "D:\\sliced\\tmp\\crawlersnap";// 快照文件根目录
    final JdbcSrchApplication dataApp = new JdbcSrchApplication(indexHome, corpusHome,snapHome);// 数据应用App
    final JdbcSrchEngine jdbc = dataApp.new JdbcSrchEngine();// jdbc风格数据操作界面

}
